package com.company.control;

import com.company.model.UserModel;
import com.company.util.MyUtils;

import javax.print.attribute.standard.OrientationRequested;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "LoginServlet", value = "/LoginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //设置编码
        request.setCharacterEncoding("utf-8");
        //获取表单数据
        String username = request.getParameter("username");
        String userpsw = request.getParameter("userpsw");

        //页面提交数据缓存到session中
        if (MyUtils.getNewInstance(UserModel.class).SelectUser(username,userpsw)){
            request.getSession().setAttribute("loginuser",username);
            //用户登录成功跳转
            request.getRequestDispatcher("/WEB-INF/views/loginTrue.jsp").forward(request,response);
        }else {
            //用户登录失败
            request.getRequestDispatcher("/WEB-INF/views/loginFalse.jsp").forward(request,response);
        }


    }


}
